package com.soft.mainsite.module.publishlog.web;

import com.soft.mainsite.common.utils.CmsUtil;
import com.soft.mainsite.module.publishlog.entity.PublishLog;
import com.soft.mainsite.module.publishlog.service.PublishLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * publishLogController.java 发布日志控制层....
 *
 * @author hujm
 * @date 2019年04月26日 15:40
 */
@Controller
@RequestMapping("/publishLog")
public class PublishLogController {

    private final Logger logger = LoggerFactory.getLogger(PublishLogController.class);

    @Autowired
    private PublishLogService publishLogService;

    /**
     * 保存日志
     *
     * @param publishLog 日志实体
     * @return
     * @author 胡佳明
     * @date 2019/4/26 19:14
     */
    @ResponseBody
    @RequestMapping("/save")
    public String savePublishLog(PublishLog publishLog){
        if (CmsUtil.isNullOrEmpty(publishLog.getLogId())){
            return publishLogService.save(publishLog);
        }
        return publishLogService.update(publishLog);
    }

    /**
     * 查看静态化发布日志(分页查询)
     *
     * @param pageNumber 当前页
     * @param pageSize  每页大小
     * @param publishLog 日志实体
     * @return 查询后的视图
     * @author 胡佳明
     * @date 2019/4/26 19:14
     */
    @RequestMapping("/list")
    public ModelAndView index(@RequestParam(value = "pageCurrent",defaultValue = "1") Integer pageNumber,
                              @RequestParam(value = "pageSize",defaultValue = "30") Integer pageSize,
                              PublishLog publishLog){
        ModelAndView view = new ModelAndView("publishlog/publishLog_list");
        view.addObject("model",publishLogService.page(pageNumber, pageSize, publishLog));
        return view;
    }

    /**
     * 删除日志
     *
     * @param ids 日志ID
     * @return 删除行数
     * @author 胡佳明
     * @date 2019/4/26 19:15
     */
    @RequestMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam(value = "ids") Integer[] ids){
        return publishLogService.delete(ids);
    }
}
